package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.setMealService;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description setMealController
 * @Author luohai
 * @Date 2024-10-04
 */
@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
public class SetMealController {

    @Autowired
    private setMealService setMealService;

    /**
     * 新增套餐
     * @param setmealDTO
     * @return
     */
    @PostMapping
    public Result addSetMeal(@RequestBody SetmealDTO setmealDTO){
        setMealService.addSetMeal(setmealDTO);
        return Result.success();
    }

    /**
     * 套餐分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result setMealPaginationQuery(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult =setMealService.setMealPaginationQuery(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 批量删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteSetMealById(@RequestParam List<Long> ids){
        setMealService.deleteSetMealById(ids);
        return Result.success();
    }

    /**
     * 根据ID查询套餐（数据回显）
     * @param setmealId
     * @return
     */
    @GetMapping("/{setmealId}")
    public Result selectSetMealById(@PathVariable Long setmealId){
        SetmealVO setmealVO=setMealService.selectSetMealById(setmealId);
        return Result.success(setmealVO);
    }

    /**
     * 根据ID修改套餐
     * @param setmealDTO
     * @return
     */
    @PutMapping
    public Result modifySetMealById(@RequestBody SetmealDTO setmealDTO){
        setMealService.modifySetMealById(setmealDTO);
        return Result.success();
    }

    /**
     * 起售停售套餐
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status,Long id){
        setMealService.startOrStop(status,id);
        return Result.success();
    }
}
